package com.ly.activiti.controller;

import com.github.pagehelper.Page;
import com.ly.activiti.domain.dto.ActTaskDTO;
import com.ly.activiti.domain.dto.ActWorkflowFormDataDTO;
import com.ly.activiti.service.IActTaskService;
import com.ly.common.core.controller.BaseController;
import com.ly.common.core.domain.AjaxResult;
import com.ly.common.core.page.PageDomain;
import com.ly.common.core.page.TableDataInfo;
import com.ly.common.core.page.TableSupport;
import org.activiti.api.task.runtime.TaskRuntime;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.ParseException;
import java.util.List;


@RestController
@RequestMapping ("/task")
public class TaskController extends BaseController {

    @Resource
    private TaskRuntime taskRuntime;

    @Resource
    private IActTaskService iActTaskService;


    //获取我的代办任务
    @GetMapping (value = "/list")
    public TableDataInfo getTasks () {
        PageDomain pageDomain = TableSupport.buildPageRequest ();
        Page<ActTaskDTO> hashMaps = iActTaskService.selectProcessDefinitionList ( pageDomain );
        return getDataTable ( hashMaps );
    }


    //渲染表单
    @GetMapping (value = "/formDataShow/{taskID}")
    public AjaxResult formDataShow (@PathVariable ("taskID") String taskID) {
        return AjaxResult.success ( iActTaskService.formDataShow ( taskID ) );
    }

    //保存表单
    @PostMapping (value = "/formDataSave/{taskID}")
    public AjaxResult formDataSave (@PathVariable ("taskID") String taskID,
                                    @RequestBody List<ActWorkflowFormDataDTO> formData) throws ParseException {
        return toAjax ( iActTaskService.formDataSave ( taskID, formData ) );

    }

}
